import { defineConfig } from "vite";
import path from 'path';
import react from '@vitejs/plugin-react';
// import dts from 'vite-plugin-dts';

function resolve(str: string) {
  return path.resolve(__dirname, str);
}

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    // dts({
    //   insertTypesEntry: true,
    //   outDir: resolve('lib'),
    //   rollupTypes: true
    // }),
  ],
  css: {
    modules: {
      localsConvention: 'camelCaseOnly',
    },
  },
  resolve: {
    alias: {
      '@packages': path.resolve(__dirname, 'packages'),
    },
  },
  build: {
    // 打包输出的目录
    outDir: 'lib',
    lib: {
      // 组件库源码的入口文件
      entry: resolve('packages/index.ts'),
      // 组件库名称
      name: 'pivot-table',
      // 文件名称, 打包结果举例: my-packages.umd.cjs
      fileName: 'index',
    },
    rollupOptions: {
      external: ['react', 'react-dom','antd'],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          react: 'react',
          'antd': 'antd',
          'react-dom': 'react-dom',
        },
        inlineDynamicImports: true,
      },
    },
  }
})

